package org.zw.store.user.api;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.zw.store.common.Result;
import org.zw.store.common.exception.BusinessException;
import org.zw.store.user.dao.LoginDao;
import org.zw.store.user.dto.LoginDto;
import org.zw.store.user.model.User;

@Slf4j //该注解会导致编译时自动创建一个日志输出对象log
@RestController
@RequestMapping("/login")
public class LoginApi {

    @Autowired
    private LoginDao loginDao;

    @PostMapping()
    public Result doLogin(@RequestBody LoginDto loginDto){ //RequestBody表示参数的格式是请求体(json格式的字符串)
        User user = loginDao.findUserByIdAndPwd(loginDto);
        if(user == null){
            //账号或密码不正确，没有查到该用户
            throw new BusinessException("账号或密码不正确");
        }

        return Result.OK();
    }
}
